package edu.ccut.saturn.basevalidate.prvalidate;

import edu.ccut.saturn.component.DefaultSaturnValidate;
import edu.ccut.saturn.component.ValidateResult;

public class IsPasswordValidate extends DefaultSaturnValidate {

	private static final String byteCharRegExpr = "[\\x00-\\xff]+";

	public void doValidate(Object value, Object[] args, ValidateResult result) {

		if (args.length >= 2) {

			int floor = 0;
			int top = 0;

			try {
				floor = Integer.parseInt(args[0].toString());
				top = Integer.parseInt(args[1].toString());
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}

			if (value.toString().length() > top
					|| value.toString().length() < floor) {
				sendError("_lengtherror_", value, result);
				return;
			}

			if (!value.toString().matches(byteCharRegExpr)) {
				sendError(_ERROR_, value, result);
			}
			 
		} else {
			sendError(_ARGERROR_, value, result);
		}
	}
}
